﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Hsinchu.Utility;
using Hsinchu.BLL;
using System.Resources;
using System.Reflection;


public partial class Admin_ItemMgr_AddItemDetail : System.Web.UI.Page
{
    //获得配置文件路径
    string xmlDocPath = HttpContext.Current.Server.MapPath("~/") + "Config/PropertyTable.xml";
    ResourceManager rm = new ResourceManager("resourceManager.Application", Assembly.GetExecutingAssembly());
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {
            InitLoad();
        }
    }


    void InitLoad()
    {
        BindProperty();
    }


    //获得属性并绑定
    void BindProperty()
    {
        ItemMgr dllItemMgr = new ItemMgr();
        DataTable dtschema = dllItemMgr.GetProperty(xmlDocPath, "root//NoteBook");
        for (int i = 0; i < dtschema.Rows.Count; i++)
        {
            //声明table行
            TableRow tr = new TableRow();
            //声明属性名称列
            TableCell tcName = new TableCell();
            //获得属性名
            tcName.Text = dtschema.Rows[i][1].ToString();
            tr.Cells.Add(tcName);
            //声明属性值列
            TableCell tcTextBox = new TableCell();
            if (dtschema.Rows[i][2].ToString() == "varchar")
            {
                TextBox tb = new TextBox();
                tb.ID = "txt" + dtschema.Rows[i][0].ToString();
                tcTextBox.Controls.Add(tb);
            }
            if (dtschema.Rows[i][2].ToString() == "int")
            {
                TextBox tb = new TextBox();
                tb.ID = "txt" + dtschema.Rows[i][0].ToString();
                tcTextBox.Controls.Add(tb);
            }
            if (dtschema.Rows[i][2].ToString() == "datetime")
            {
                TextBox tb = new TextBox();
                tb.ID = "txt" + dtschema.Rows[i][0].ToString();
                tcTextBox.Controls.Add(tb);
            }
            tr.Controls.Add(tcTextBox);
            //声明属性空验证列
            TableCell tcRequiredFieldValidator = new TableCell();
            RequiredFieldValidator rfv = new RequiredFieldValidator();
            rfv.ErrorMessage = rm.GetString("RequiredFieldErrorMessage");
            rfv.ControlToValidate = "txt" + dtschema.Rows[i][0].ToString();
            tcRequiredFieldValidator.Controls.Add(rfv);
            tr.Cells.Add(tcRequiredFieldValidator);

            //声明属性类型验证列
            TableCell tcCompareValidator = new TableCell();
            CompareValidator cv = new CompareValidator();
            cv.Operator = ValidationCompareOperator.DataTypeCheck;
            cv.ErrorMessage = rm.GetString("CompareValidatorErrorMessage");
            tableContainer.Rows.Add(tr);
            
        }

    }
}
